package homework;
//作业标题(2742)
//对称二叉树
//
//作业内容
//对称二叉树
//https://leetcode.cn/problems/symmetric-tree/description/
public class h2742 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true;
        return _isSymmetric(root.left, root.right);
    }
    private boolean _isSymmetric(TreeNode left, TreeNode right)
    {
        if(left == null && right == null) return true;
        if(left == null && right != null || left != null && right == null) return false;

        return left.val == right.val && _isSymmetric(left.left,right.right) && _isSymmetric(left.right, right.left);
    }
}
